package fix;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;

import com.swf.seed.regex.PatternUtils;
import com.swf.seed.triutil.lang.SdFileUtils;

public class XmlCreate {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		Map<String, String> map = getMap("map.txt");
		Map<String, String> fix = getMap("fix.txt");
		String value ;
		String describe;
		for (String key:fix.keySet()){
			value = map.get(key);
			describe = fix.get(key);
			if (value == null){
				value = "";
			}
			if (describe == null){
				describe = "";
			}
			System.out.println("<column name=\""+key+"\" value=\""+value+"\" describe=\""+describe+"\"/>");
		}
		
	}

	/**
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	private static Map<String,String> getMap(String fileName) throws IOException, FileNotFoundException {
		File file = SdFileUtils.getFile(fileName);
		String content = IOUtils.toString(new FileReader(file));
		List<String> list = PatternUtils.matchedList(content, "\\S+\\s+\\S+");
		Map<String,String> map = new LinkedHashMap<String,String>(); 
		for (String l:list){
			map.put(l.split("\\s+")[0], l.split("\\s+")[1]);
		}
		return map;
	}
}
